To allow your program to run on machines that don't have the Name Registry, you should weak link to "NameRegistryLib". You can then determine whether the Name Registry is available by testing the address of a symbol in the library against kUnresolvedCFragSymbolAddress. This technique is documented in Inside Macintosh: PowerPC System Software, p1-25.
The following snippet demonstrates both techniques:
static Boolean HasPCISlots(void) // Returns true if the machine has any PCI slots. Guards against the // absence of NameRegistryLib, so you can run this function on any PPC // computer. { Boolean result; RegEntryIter myIterator; OSStatus err; Boolean done; RegEntryID foundEntry; // Assume the worst. result = false; // Check that the link to NameRegistryLib was successfull. if (RegistryEntryIterateCreate != kUnresolvedCFragSymbolAddress) { // Create an iterator if (RegistryEntryIterateCreate(&myIterator) == noErr) { // Search for a node of type "pci". (void) RegistryEntryIDInit(&foundEntry); err = RegistryEntrySearch(&myIterator, kRegIterContinue, &foundEntry, &done, "device_type", "pci", sizeof("pci")); // See whether we found one. if (err == noErr && !done) { result = true; (void) RegistryEntryIDDispose(&foundEntry); } (void) RegistryEntryIterateDispose(&myIterator); } } return (result); }
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help